/**
 *
 */
package com.googlecode.pkchat.pkserver;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author Simon Pratt
 *
 */
public class EchoService implements Runnable {

	Socket s;
	Scanner in;
	PrintWriter out;

	/**
	 *
	 */
	public EchoService(Socket aSocket,PrintWriter out) {
		this.s = aSocket;
		this.out = out;
	}

	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		try{
			try{
				in = new Scanner(s.getInputStream());
				doService();
			}
			finally{
				s.close();
			}
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	public void doService() throws IOException
	{
		String message = "medium";
		while(true){
			if(!in.hasNextLine()) return;
			message = in.nextLine();
			out.println(message);
			System.out.println(message);
			out.flush();
		}
	}
}
